package com.zhugang.week02;

/**
 * @program algorithms
 * @description: linkedList
 * @author: chanzhugang
 * @create: 2022/04/17 23:20
 */
public class DoubleMyLinkedList {

    public class Node {
        public int data;
        private Node prev;
        private Node next;
    }

    private final Node head = null;

    /**
     * O(1)
     * @param head
     * @param p
     * @return
     */
    public Node deleteThisNode(Node head, Node p) {
        if (head == null || p == null) {
            return null;
        }
        if (p == head) {
            head = head.next;
            if (head != null) {
                head.prev = null;
                return head;
            }
        }
        p.prev.next = p.next;
        p.next.prev = p.prev;
        return head;
    }

}